package com.itheima.mapper;

import com.itheima.domain.Dept;
import com.itheima.domain.Emp;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface DeptMapper {

    @Select("select * from DEPT")
    @Results({
            @Result(id=true,column = "deptno", property = "deptno"),
            @Result(column = "dname", property = "dname"),
            @Result(column = "loc", property = "loc"),
            @Result(
                    //property = "empList",             // 被包含对象的变量名
                    //javaType = Emp.class,    // 被包含对象的实际数据类型
                    //column = "deptno",             // 根据查询出的DEPT表中的deptno字段来查询EMP表
                    /*
                        one、@One 一对一固定写法
                        select属性：指定调用哪个接口中的哪个方法
                     */
                    //one = @One(select = "com.itheima.mapper.EmpMapper.selectById")

                    property = "empList",  // 被包含对象的变量名
                    javaType = List.class,  // 被包含对象的实际数据类型
                    column = "deptno",          // 根据查询出的DEPT表中的deptno字段来查询EMP表
                    /*
                        many、@Many 一对多查询的固定写法
                        select属性：指定调用哪个接口中的哪个查询方法
                     */
                    many = @Many(select = "com.itheima.mapper.EmpMapper.selectById", fetchType = FetchType.LAZY)
            )
    })
    List<Dept> findAll();
}
